import 'package:base_flutter/base_flutter.dart';
import 'package:decimal/decimal.dart';

extension MealListExInfo on List {
  List<T> takeWhere<T>(bool Function(T element) test) {
    var list = <T>[];
    for(var item in this){
      if(test(item)){
        list.add(item);
      }
    }
    return list;
  }
}

extension DateStringExt on String{
  String formatDate(List<String> format){
    var date = DateTime.tryParse(this.trim());
    if(date!=null){
      return date.toDateStr(format);
    }else{
      return this;
    }
  }
}

extension NumExtInfo on num {
  Decimal get d => Decimal.parse(this.toString()).round(scale: 2);
}